<?php

declare(strict_types=1);

namespace App\Library\Task\library\queue;

use App\Constants\ErrorCode;
use App\Exception\BusinessException;
use App\Library\Log\Log;
use App\Library\Task\library\queue\drivers\mns\QueueServerMns;
use App\Library\Task\library\queue\drivers\redis\QueueServerRedis;

class QueueServer
{
    private $_server;

    public function __construct()
    {
        $queueDriver = config('goods.task_drivers_default.queue_driver');
        switch ($queueDriver) {
            case 'redis':
                Log::info(new BusinessException(ErrorCode::OTHER_ERR, 'QueueServer 队列选择：QueueServerRedis'));
                $this->_server = new QueueServerRedis();
                break;
            case 'mns':
                $this->_server = new QueueServerMns();
                Log::info(new BusinessException(ErrorCode::OTHER_ERR, 'QueueServer 队列选择：QueueServerMns'));
                break;
            default:
                $this->_server = new QueueServerRedis();
                break;
        }
    }

    public function pop($key, $time) {
        return $this->_server->pop($key, $time);
    }

    public function scan($driver = 'default') {
        return $this->_server->scan($driver);
    }

    public function clear( $driver = 'default' ) {
        return $this->_server->clear($driver);
    }
}